package cn.com.linht.jsontosql.util;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @author linht
 */
public class JsonFileUtils {


        /**
         * 根目录是testNg/json
         *
         * @param resourcesUrl
         * @return
         */
        public static String getStringValue(String resourcesUrl)  {
            String dataFileCharset = "UTF-8";
            try(InputStream in = JsonFileUtils.class.getClassLoader().getResourceAsStream(resourcesUrl);
                InputStreamReader inputStreamReader = new InputStreamReader(in, dataFileCharset);
                BufferedReader br = new BufferedReader(inputStreamReader);){
                StringBuilder buffer = new StringBuilder();
                String line;
                while ((line = br.readLine()) != null) {
                    buffer.append(line);
                }
                return buffer.toString();
            }catch (IOException e){
                System.out.println("文件读取失败,文件路径为"+resourcesUrl);
                throw new RuntimeException(e);
            }
        }

}
